
<template>
	<div>
		<div>
			<h2>欢迎登录,{{username}}</h2>
			<el-button type="primary" @click="logout">注销</el-button>
		</div>
	</div>
</template>

<script >
import axios from "axios";

export default {
	name: "Home",
	data(){
		return{
			username : localStorage.getItem('username')
		}
	},
	methods:{
		logout(){
			const token = localStorage.getItem('token')
			axios({
				url: 'http://localhost:9000/user/logout/' + token, // 后端接口URL
				method: 'GET'
			}).then(res => {
				this.$message.success("退出成功!")
				this.$router.push('/');
			}).catch((error) => {
				console.error('Error fetching captcha:', error);
			});
		}
	}
}
</script>

<style scoped lang="scss">

</style>